//
//  Statues.swift
//  新浪微博
//
//  Created by mac on 15/12/1.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class Statues: NSObject {
//微博创建时间
    var created_at: String?
    //微博id
    var id: Int = 0
    //微博正文
    var text: String?
    //微博来源
    var source: String?
    //user属性
    var user: User?
    //配图属性
    var pic_urls: [[String: String]]?{
        didSet{
        //给imageURL赋值
            guard let urls = pic_urls else {
            return
            }
            //实例化imageurls
            imageURLs = [NSURL]()
            //遍历urls
            for item in urls{
            let urlString = item["thumbnail_pic"]
                let url = NSURL(string: urlString!)
                imageURLs?.append(url!)
            }
        }
    }
    
    var imageURLs: [NSURL]?
    //构造方法,kvc设置初始值
    init(dict: [String: AnyObject]){
    super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
           if let dict = value as? [String : AnyObject]{
            //字典转模型
            user = User(dict: dict)
            }
            return
        }
        //一定要注意,一定要掉用super
        super.setValue(value, forKey: key)
    }
    //过滤
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    //重写description 属性
    override var description: String{
        let keys = ["created_at","id","text","source"]
        return dictionaryWithValuesForKeys(keys).description
    }
}
